<?php if (!defined('BASEPATH'))exit('No direct script access allowed');
header('Access-Control-Allow-Origin:http://www.tan66.com'); 
header('Access-Control-Allow-Methods:GET');  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  
/**
 * 获取用户投资记录定时任务
 */
class ExperAward extends MY_Controller {
    
    //定时获取满标投资记录任务平台
    private $success_invests_plats = array("koudailc","ronghedai","51rz","jiurong","gaosouyi","he-pai");//口袋理财，融和贷
    //定时获取投资记录待收本金平台
    private $invests_oids_plats = array("jiurong","gaosouyi","he-pai");

    function __construct() {
        parent::__construct();
        $this->load->model('exper_award_model');
        $this->load->model('plat_award_list_model');
    }
    function rjb777() {
        $nameEn = "rjb777";
        $plat = $this->exper_award_model->get_plat(array('name_en'=>$nameEn));
        echo date("Y-m-d H:i:s");die;
        if($plat){
            $platID = $plat['id'];//平台id
            //平台体验规则
            $rules = $this->exper_award_model->get_rules(array('plat_id'=>$platID));
            
            $accessKey = $plat['access_key'];
            $getData = array();//请求参数
            /*****构造请求参数****/
            $getData['from'] = "tanliuliu";
            $getData['timestamp'] = time();
            $sign = strtolower(md5($accessKey.$getData['from'].$getData['timestamp'].$accessKey));
            $getData['sign'] = $sign;
            /*****构造请求参数****/
            $queryUrl ="http://api.rjb777.com/api/TLLServices/ALL";//查询接口
            $result = $this->crypt->GET_Api($queryUrl,$getData);//发送GET查询请求,并获取请求结果
            $result = json_decode($result,true);
            p($result);die;
            if($result && $result != null && $result['status'] == 0){//验证返回结果的合法性
                $userList = $result['list'];//获取用户列表
                if($userList && $userList != null && $userList != "" && count($userList) > 0){//验证用户列表的合法性
                    foreach ($userList as $key => $user){
                        $usernamep = $user['usernamep'];//B平台唯一标识
                        $level = $user['level'];
                        $cpa = $this->exper_award_model->check_ab_cpa(array('usernamep'=>$usernamep,'plat_id'=>$platID));
                        if($cpa){
                            $userID = $cpa['user_id'];//平台用户ID
                            /****************绑定数据********************/
                            if($cpa['is_data_bind'] == 0 && $level == 1){
                                $cpa_data = array();
                                $cpa_data['is_data_bind'] = 1;
                                $status = $this->exper_award_model->update_ab_cpa($cpa_data,$cpa['id']);
                                if($status){//更新成功
                                    //获取平台预付款
                                    $plat_temp = $this->exper_award_model->get_plat(array('id'=>$platID));
                                    
                                    $rule_one = $rules[0];   
                                    $data = array();
                                    $data['user_id'] = $userID;
                                    $data['plat_id'] = $platID;
                                    $data['rule_step'] = 1;
                                    $data['award'] = $rule_one['award'];
                                    $data['exper'] = $rule_one['exper'];
                                    $data['desc'] = $rule_one['rule'];
                                    $data['create_time'] = time();
                                    $this->plat_award_list_model->insert($data);
                                    //更新平台信息
                                    $plat_data = array();
                                    $plat_data['pay_amount'] = $plat_temp['pay_amount'] - $rule_one['true_amount'];
                                    $this->exper_award_model->update_plat($plat_data,$platID);
                                    //添加平台体验日志
                                    $plat_log = array();
                                    $plat_log['user_id'] = $userID;
                                    $plat_log['plat_id'] = $platID;
                                    $plat_log['plat_balance'] = $plat_data['pay_amount'];
                                    $plat_log['award'] = $data['award'];
                                    $plat_log['true_award'] = $rule_one['true_amount'];
                                    $plat_log['experience'] = $data['exper'];
                                    $plat_log['create_time'] = time();
                                    $this->exper_award_model->insert_plat_log($plat_log);
                                    
                                    //发送奖励通知
                                    $message = "您已经完成【".$plat['name_ch'].'】平台第1步【'.$rule_one['rule']."】的体验,将获得<span class='mail-award'>".$rule_one['award']."溜溜币</span>和<span class='mail-award'>".$rule_one['exper']."积分</span>,赶快去<a href='/user/try_list.html' class='mail-award-a'>立即领取&gt;&gt;</a>吧。感谢您对弹溜溜的支持！";
                                    $message = mail_notice_tpl($this->config_tpl['mail_tpl'], $message);
                                    $this->db->insert("users_award_notice", array('user_id'=>$userID,'title'=>'奖励通知','content'=>$message,'from'=>'弹溜溜官方','create_time'=>  time()));
                                }
                            }
                            /****************绑定数据********************/
                            //投资数据处理
                            $investList = $user['list'];
                            if($investList && $investList != null && $investList != "" && count($investList) > 0){//验证用户投资记录
                                $count = count($investList);//总记录数
                                foreach ($investList as $key => $invest){
                                    $last_index = $key + 1;//最后一条记录
                                    /****************处理首投金额********************/
                                    if($last_index == $count  && intval($cpa['amount']) == 0){
                                        //获取平台预付款
                                        $plat_temp = $this->exper_award_model->get_plat(array('id'=>$platID));
                                        $first_amount = intval($invest['amount']);//首投金额
                                        foreach ($rules as $k => $rule) {
                                            $step_index = $rule['step'];
                                            $max_amount = $rule['max_amount'];
                                            $min_amount = $rule['min_amount'];
                                            if($min_amount <= $first_amount && $first_amount <=  $max_amount ){
                                                $true_amount = $rule['true_amount'];//实际扣除金额
                                                $award_amount = $rule['award'];//奖励金额
                                                $exper_amount = $rule['exper'];//奖励经验
                                                //增加奖励记录
                                                $award_list = array();
                                                $award_list['user_id'] = $userID;
                                                $award_list['plat_id'] = $platID;
                                                $award_list['rule_step'] = $step_index;
                                                $award_list['award'] = $award_amount;
                                                $award_list['exper'] = $exper_amount;
                                                $award_list['desc'] = '首次产品体验金额'.  sprintf('%0.2f',$first_amount).'元';
                                                $award_list['create_time'] = time();
                                                $invest_result = $this->plat_award_list_model->insert($award_list);
                                                if($invest_result){//添加成功
                                                    //更新绑定信息
                                                    $cpa_data = array();
                                                    $cpa_data['amount'] = $first_amount;
                                                    $cpa_data['is_finish'] = 1;
                                                    $this->exper_award_model->update_ab_cpa($cpa_data,$cpa['id']);
                                                    //更新平台信息
                                                    $plat_data = array();
                                                    $plat_data['pay_amount'] = $plat_temp['pay_amount'] - $true_amount;
                                                    if($plat_data['pay_amount'] <= 10000000){
                                                        $plat_data['is_show'] = 0;
                                                    }
                                                    $this->exper_award_model->update_plat($plat_data,$platID);
                                                    //添加平台体验日志
                                                    $plat_log = array();
                                                    $plat_log['user_id'] = $userID;
                                                    $plat_log['plat_id'] = $platID;
                                                    $plat_log['plat_balance'] = $plat_data['pay_amount'];
                                                    $plat_log['award'] = $award_amount;
                                                    $plat_log['true_award'] = $true_amount;
                                                    $plat_log['experience'] = $exper_amount;
                                                    $plat_log['create_time'] = time();
                                                    $this->exper_award_model->insert_plat_log($plat_log);
                                                    
                                                    //发送奖励通知
                                                    $message = "您已经完成【".$plat['name_ch'].'】平台第'.$step_index.'步【'.$rule['rule']."】的体验,将获得<span class='mail-award'>".$award_amount."溜溜币</span>和<span class='mail-award'>".$exper_amount."积分</span>,赶快去<a href='/user/try_list.html' class='mail-award-a'>立即领取&gt;&gt;</a>吧。感谢您对弹溜溜的支持！";
                                                    $message = mail_notice_tpl($this->config_tpl['mail_tpl'], $message);
                                                    $this->db->insert("users_award_notice", array('user_id'=>$userID,'title'=>'奖励通知','content'=>$message,'from'=>'弹溜溜官方','create_time'=>  time()));
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    /****************处理首投金额********************/
                                    /****************处理投资记录********************/
                                    $where = array();
                                    $where['user_id'] = $userID;
                                    $where['plat_id'] = $platID;
                                    $where['order_nid'] = $invest['oid'];
                                    $invest_ord = $this->exper_award_model->get_plat_invest($where);
                                    //投标订单不存在
                                    if(!$invest_ord){
                                        $invest_data = array();
                                        $invest_data['user_id'] = $userID;
                                        $invest_data['plat_id'] = $platID;
                                        $invest_data['order_nid'] = $invest['oid'];
                                        $invest_data['borrow_nid'] = $invest['bid'];
                                        $invest_data['title'] = $invest['title'];
                                        $invest_data['url'] = $invest['url'];
                                        $invest_data['amount'] = $invest['amount'];
                                        $invest_data['invest_time'] = $invest['investtime'];
                                        $invest_data['period'] = $invest['period'];
                                        $invest_data['unit'] = $invest['unit'];
                                        $invest_data['rate'] = $invest['rate'];
                                        $invest_data['create_time'] = time();
                                        $this->exper_award_model->insert_plat_invest_list($invest_data);
                                    }
                                    /****************处理投资记录********************/
                                }
                            }
                        }
                    }      
                    echo "访问".$nameEn."日志[".date('Y-m-d H:i:s')."]:".'数据处理完毕';
                }else{
                    echo "访问".$nameEn."日志[".date('Y-m-d H:i:s')."]:"."没有查询到用户（".$usernamep."）记录";
                }
            }else{
                echo "访问".$nameEn."日志[".date('Y-m-d H:i:s')."]:".'访问出错';
            }
        }else{
            echo "访问".$nameEn."日志[".date('Y-m-d H:i:s')."]:".'平台不存在';
        }
    }

    /**
     * 定时获取平台前一天用户满标投资记录
     */
    function getSuccessInvestsTask(){
        if(!$this->success_invests_plats){//定时任务目标平台
            echo "";die;
        }
        //前一天时间
        $yesterday_date = date("Y-m-d",strtotime("-1 day"));//
        $start_time = strtotime($yesterday_date." 00:00:00");//前一天起始时间
        $end_time = strtotime($yesterday_date." 23:59:59");//前一天结束时间
        //指定日期获取记录
        if(isset($_GET['date']) && $_GET['date']){
            $start_time = strtotime($_GET['date']." 00:00:00");
            $end_time = strtotime($_GET['date']." 23:59:59");
        }
        //指定平台获取记录
        if(isset($_GET['plat']) && $_GET['plat']){
            $this->success_invests_plats = array();
            $this->success_invests_plats[0] = $_GET['plat'];
        }
        //扫描平台
        foreach ($this->success_invests_plats as $key=>$plat_en){
            $plat = $this->db->query("select `id`,`name_ch`,`name_en`,`access_key`,`add_interest`,`plat_type`,`max_require_amount`,`min_require_amount`,`min_require_period`,`require_period_type` from `tan_plat` where `name_en` = '$plat_en' order by `id` desc limit 1")->row_array();
            if(!$plat) continue;//结束本次循环
            //获取平台用户满标投资记录接口数据
            $success_invest_link = $this->db->query("select `plat_en`,`success_invest_link` from `tan_plat_interface` where `plat_en` = '$plat_en' order by `id` desc limit 1")->row_array();
            $success_invest_link = $success_invest_link['success_invest_link'];
//            echo $success_invest_link;die;
            //构造请求数据
            $postData = array();
            $postData['from'] = "tan66";
            $postData['starttime'] = $start_time;
            $postData['endtime'] = $end_time;
            $postData['timestamp'] = time();
            $sign = md5($plat['access_key'].$postData['from'].$postData['timestamp'].$plat['access_key']);//计算sign
            $postData['sign'] = $sign;
            //发送http请求句柄,并返回结果
            $result = $this->crypt->GET_Api($success_invest_link,$postData);
//            p($result);die;
            $result = json_decode($result,true);
//            p($result);die;
            if($result && is_array($result) && $result['status'] != 1 && $result['status'] == 0 || isset($result['list'])){
                $total_amount = 0;
                $list = $result['list'];
                if(!$list) continue;
                foreach ($list as $k=>$val){
                    
                    $amount_status = 1;//投资金额是否满足要求
                    $peroid_status = 1;//投资期限是否满足要求
                    $plat_status = 1;//平台类型是否满足要求
                    
                    $uinfo = $val["uinfo"];
                    //查找cpa
                    $user = $this->db->query("select `user_id`,`plat_en` from `tan_plat_ab_cpa` where `plat_en` = '$plat_en' and `usernamep` = '$uinfo[usernamep]'")->row_array();
                    
                    if($plat['plat_type'] == 1){//AB首投模式
                        //验证是否存在投资记录
                        $invest_list_flag = $this->db->select("*")->from("tan_plat_invest_list")->where(array("plat_en"=>$plat_en,"user_id"=>$user['user_id']))->order_by("id desc")->get()->num_rows();
                        $plat_status = $invest_list_flag ? 0 : 1;
                    }
                    
                    //验证该投资记录是否存在
                    $flag = $this->db->select("*")->from("tan_plat_invest_list")->where(array("plat_en"=>$plat_en,"order_nid"=>$val['oid'],"user_id"=>$user['user_id']))->order_by("id desc")->get()->num_rows();
                    if($flag) continue;
                    
                    //构造投资记录
                    $data = array();
                    $data["user_id"] = $user['user_id'];
                    $data["plat_id"] = $plat['id'];
                    $data["plat_en"] = $plat_en;
                    $data["order_nid"] = $val['oid'];
                    $data["borrow_nid"] = $val['bid'];
                    $data["title"] = $val['title'];
                    $data["url"] = $val['url'] ? $val['url'] : "";
                    $data["amount"] = $val['amount'];
                    $data["invest_time"] = $val['invest_time'];
                    $data["success_time"] = $val['success_time'] ?  $val['success_time'] : 0;
                    $data["expire_time"] = $val['expire_time'] ? $val['expire_time'] : 0;
                    $data["period"] = $val['period'] ? $val['period'] : 0;
                    $data["unit"] = $val['unit'] ? $val['unit'] : 0;
                    $data["rate"] = $val['rate'];
                    $data["create_time"] = time();
                    //插入投资记录
                    $this->db->insert("tan_plat_invest_list",$data);
                    $insert_id = $this->db->insert_id();
                    //添加到计息定时任务列表
                    $status = 1;
                    $amount = $val['amount'];//投资金额
                    //最大限额
                    if($plat['max_require_amount'] && $val['amount'] && $val['amount'] > $plat['max_require_amount']){
                        $amount_status = 1;
                        $amount = $plat['max_require_amount'];
                    }
                    //最小限额
                    if($plat['min_require_amount'] && $val['amount'] && $val['amount'] < $plat['min_require_amount']){
                        $amount_status = 0;
                    }
                    //最小期限限定
                    if($plat['min_require_period']){
                        $peroid_status = $data["period"] < $plat['min_require_period'] ? 0 : 1;
                    }
                    //最大期限限定
                    if($plat['max_require_period']){
                        $peroid_status = $data["period"] > $plat['max_require_period'] ? 0 : 1;
                    }
                    
                    $total_amount += $amount;
                    
                    if($amount_status && $peroid_status && $plat_status){
                        $status = 1;
                    }else{
                        $status = 0;
                    }
                    
                    $task_data = array();
                    $task_data['invest_id'] = $insert_id;//投资记录id
                    $task_data['oid_platen'] = $data["order_nid"]."_".$plat_en;//记录编号
                    $task_data['title'] = $data['title'];//投资记录标题
                    $task_data['oid_id'] = $data["order_nid"];//记录订单编号
                    $task_data['user_id'] = $data["user_id"];//投资用户id
                    $task_data['plat_en'] = $data["plat_en"];//平台
                    $task_data['total_amount'] = $data["amount"];//总投资额
                    $task_data['amount'] = $amount;//有效计息投资额
                    $task_data['total_interest_finance'] = 0;//总加息获得奖励
                    $task_data['total_interest_exper'] = 0;
                    $task_data['expire_time'] = $data["expire_time"];//到期时间
                    $task_data['invest_time'] = $data["invest_time"];//投资时间
                    $task_data['add_interest'] = $plat['add_interest'];//弹溜溜固定加息
                    $task_data['status'] = $status;//加息状态（1正在计息中，0计息结束）
                    $this->db->insert("tan_plat_invest_task",$task_data);//添加到计息任务队列中
                }
                
                if($total_amount){
                    $this->db->query("update tan_plat_info set total_amount = total_amount + $total_amount where plat_en = '$plat_en'");
                }
                
            }else{
                //TODO发送网络异常手机短信通知
                echo "[".date("Y-m-d H:i:s")."]".$plat['name_ch']."满标接口获取异常，异常原因：".$result['errmsg'];
                continue;
            }
            echo json_encode(array("status"=>1));
        }
    }
    /**
     * 每日计息定时器任务
     */
    function everydayAddInterestTask(){
        exit("--------------------每日计息定时器任务 关闭--------------------------");
        //消息类型配置
        $notice_type_cf = $this->web_config['MSGTYPE'];
        
        $today_time = strtotime(date("Y-m-d")." 00:00:00");//当天起始时间戳
        //获取当天没有计息的所有任务
        $tasks = $this->db->query("select `tan_plat_invest_task`.*,`tan_users`.username,`tan_users`.email,`tan_users`.mobile from `tan_plat_invest_task` left join `tan_users` on `tan_users`.`user_id` = `tan_plat_invest_task`.`user_id`  where `tan_plat_invest_task`.`status` = 1 and `tan_plat_invest_task`.`interest_time` < $today_time order by id asc")->result_array();
        //计息全部结束
        if(!$tasks){
           echo "";die; 
        }
        //循环每个计息任务，执行计息操作
        foreach ($tasks as $key => $val){
            //平台信息
            $plat = $this->db->query("select `name_ch`,`id` from `tan_plat` where `name_en` = '$val[plat_en]' order by id desc limit 1")->row_array();
            if(!$val['amount']){//待收本金为0
                //发送站内信通知
                $message = "尊敬的弹溜溜用户$plat[username]：您于".date("Y-m-d H:i:s",$val['invest_time'])."在".$plat['name_ch']."平台投资的记录（标的名称：".$val['title']."，投资编号：A".encrypt_interests_id($val['id'])."）已加息结束，总获取弹溜溜官方加息奖励".$val['total_interest_finance']."溜溜币（其中固定加息奖励$val[interest_fixed]溜溜币，加息券加息奖励$val[interest_extra]溜溜币）。感谢您对弹溜溜官方的支持！";
                insert_award_notice(array('user_id'=>$val['user_id'],'title'=>'加息结束通知','content'=>$message,'from'=>'弹溜溜官方','create_time'=>  time()),$notice_type_cf['sms_type']);
                $this->db->query("update tan_plat_invest_task set `status` = 0 where `invest_id` = $val[invest_id]");
                continue;
            }
            
            //计算加息开始
            $add_interest = $val['add_interest'];//平台固定加息
            //计算溜溜币加息
            $add_finance = intval((floatval($val['amount']) * $add_interest / 365) * 10000);
            //额外加息
            $extra_finance = 0;
            if($val['extra_interest']){
                $extra_finance = intval((floatval($val['amount']) * $val['extra_interest'] / 365) * 10000);//平台额外加息
            }
            $finance = intval($add_finance + $extra_finance);//总加息
            
            //计算积分加息
            $exper = 0;
            if($finance){
                $this->db->trans_begin();//开启事务
                
                //加息时间
                $interest_time = time(); 
                //加息详情明细数据
                $interest_detail = array("invest_id"=>$val['invest_id'],"user_id"=>$val['user_id'],"total_finance"=>$finance,"fixed_finance"=>$add_finance,"extra_finance"=>$extra_finance,"exper"=>$exper,"create_time"=>$interest_time);
                $this->db->insert("tan_plat_interest_detail",$interest_detail);
                $query1 = $this->db->insert_id();
                
                //更新投资记录总的加息奖励
                $val['total_interest_finance'] = $val['total_interest_finance'] + $finance;
                $val['interest_fixed'] = $val['interest_fixed'] + $add_finance;
                $val['interest_extra'] = $val['interest_extra'] + $extra_finance;
                $query0 = $this->db->query("update `tan_plat_invest_task` set `total_interest_finance` = $val[total_interest_finance],`interest_fixed` = $val[interest_fixed],`interest_extra` = $val[interest_extra],`interest_time` = $interest_time where `invest_id` = $val[invest_id]");
                
                //获取账户信息
                $account = $this->db->query("select * from tan_account where `user_id` = $val[user_id]")->row_array();
                $account_data = array();
                $account_data['total'] = $account['total'] + $finance;
                $account_data['balance'] = $account['balance'] + $finance;
                $account_data['experience'] = $account['experience'] + $exper;
                $account_data['experience_balance'] = $account['experience_balance'] + $exper;
                $query2 = $this->db->where(array("user_id"=>$val['user_id']))->update("tan_account",$account_data);
                
                //添加溜溜币记录
                $finance_data = array();
                $finance_data['user_id'] = $val['user_id'];
                $finance_data['content'] = '投资记录[编号:A'.  encrypt_interests_id($val['id']).']的每日固定加息奖励'.$add_finance.'溜溜币'.($extra_finance ? ',加息券奖励'.$extra_finance.'溜溜币' : "");
                $finance_data['finance'] = $finance;
                $finance_data['finance_balance'] =  $account_data['balance'];
                $finance_data['reward_type'] = 'interest_award';
                $finance_data['type'] = 1;
                $finance_data['create_time'] = time();
                $finance_data['month'] = date("Ym");
                $finance_data['day'] = date("Ymd");
                $this->db->insert("tan_finance_list",$finance_data);
                $query3 = $this->db->insert_id();
                
                //添加积分记录
                if($exper){
                    $experience_data = array();
                    $experience_data['user_id'] = $val['user_id'];
                    $experience_data['content'] = '新人注册奖励礼包'.$exper.'积分';
                    $experience_data['experience'] = $exper;
                    $experience_data['experience_balance'] = $account_data['experience_balance'];
                    $experience_data['reward_type'] = 'interest_award';
                    $experience_data['type'] = 1;
                    $experience_data['create_time'] = time();
                    $experience_data['month'] = date("Ym");
                    $experience_data['day'] = date("Ymd");
                    $this->db->insert("tan_experience_list",$experience_data);
                    $query4 = $this->db->insert_id();
                }else{
                    $query4 = 1;
                }
                
                //发送站内信通知
                $message = "尊敬的弹溜溜用户$plat[username]：您在".$plat['name_ch']."平台投资的记录（标的名称：".$val['title'].",投资编号：A".encrypt_interests_id($val['id'])."）今日（".date("Y-m-d")."）加息奖励".$finance."溜溜币（其中固定加息奖励".$add_finance."溜溜币".($extra_finance ? "，加息券加息奖励".$extra_finance."溜溜币" : "")."）！";
                insert_award_notice(array('user_id'=>$val['user_id'],'title'=>'加息通知','content'=>$message,'from'=>'弹溜溜官方','create_time'=>  time()),$notice_type_cf['sms_type']);
                $query5 = $this->db->insert_id();
                
                if($query0 && $query1 && $query2 && $query3 && $query4 && $query5){
                    $this->db->trans_commit();//事务回滚
                }else{
                    $this->db->trans_rollback();//事务提交
                }
            }
            
            //加息结束
            if($val['expire_time'] && $val['expire_time'] <= $today_time){
                //发送站内信通知
                $message = "尊敬的弹溜溜用户$plat[username]：您于".date("Y-m-d H:i:s",$val['invest_time'])."在".$plat['name_ch']."平台投资的记录（标的名称：".$val['title']."，投资编号：A".encrypt_interests_id($val['id'])."）已加息结束，总获取弹溜溜官方加息奖励".$val['total_interest_finance']."溜溜币（其中固定加息奖励$val[interest_fixed]溜溜币，加息券加息奖励$val[interest_extra]溜溜币）。感谢您对弹溜溜官方的支出！";
                insert_award_notice(array('user_id'=>$val['user_id'],'title'=>'加息结束通知','content'=>$message,'from'=>'弹溜溜官方','create_time'=>  time()+10),$notice_type_cf['sms_type']);
                $this->db->query("update tan_plat_invest_task set `status` = 0 where `invest_id` = $val[invest_id]");
            }
        }
        
        echo "[".date("Y-m-d H:i:s")."]计息结束。";
    }
    /**
     * 获取投资订单待收本金接口任务
     */
    function getInvestsOidsAmountTask(){
        //有效检测平台
        if(!$this->invests_oids_plats){
            echo "";die;
        }
        //指定平台
        if(isset($_GET['plat']) && $_GET['plat']){
            $this->invests_oids_plats = array(0=>$_GET['plat']);
        }
        //循环平台，处理待收本金
        foreach ($this->invests_oids_plats as $key=>$plat_en){
            $plat = $this->db->query("select `id`,`name_ch`,`name_en`,`access_key`,`add_interest`,`plat_type`,`max_require_amount`,`min_require_amount` from `tan_plat` where `name_en` = '$plat_en' order by `id` desc limit 1")->row_array();
            if(!$plat) continue;//结束本次循环
            //获取查询平台用户投资记录待收本金接口
            $invest_amount_link = $this->db->query("select `plat_en`,`invest_amount_link` from `tan_plat_interface` where `plat_en` = '$plat_en' order by `id` desc limit 1")->row_array();
            $invest_amount_link = $invest_amount_link['invest_amount_link'];
            
            //查询平台投资记录订单
            $invest_oids_arr = $this->db->query("select `oid_id` from `tan_plat_invest_task` where `plat_en` = '$plat_en'  and `status` = 1 order by `id` asc")->result_array();
            if(!$invest_oids_arr) continue;
            $oids_str = "";
            foreach ($invest_oids_arr as $oid_arr){
                $oids_str .= $oid_arr['oid_id'].",";
            }
            $oids_str = rtrim($oids_str,",");
            //构造请求数据
            $postData = array();
            $postData['from'] = "tan66";
            $postData['oids'] = $oids_str;
            $postData['timestamp'] = time();
            $sign = md5($plat['access_key'].$postData['from'].$postData['oids'].$postData['timestamp'].$plat['access_key']);//计算sign
            $postData['sign'] = $sign;
            
            //发送http请求句柄,并返回结果
            $result = $this->crypt->GET_Api($invest_amount_link,$postData);
            $result = json_decode($result,true);
            if($result && is_array($result) && $result['status'] != 1 && $result['status'] == 0){
                $list = $result['list'];
                if(!$list) continue;
                $data = array();
                foreach ($list as $val){
                    $oid_id = $val['oid'];//投资记录编号
                    $amount = $val['amount'];//投资记录待收本金
                    $temp = array();
                    $temp['oid_platen'] = $oid_id."_".$plat_en;
                    $temp['amount'] = $amount;
                    $data[] = $temp;
                }
                //批量更新数据
                $this->db->update_batch("tan_plat_invest_task",$data,"oid_platen");
                
            }else{
                //TODO发送网络异常手机短信通知
                echo "[".date("Y-m-d H:i:s")."]".$plat['name_ch']."投资记录待收本金接口获取异常，异常原因：".$result['errmsg'];
                continue;
            }
        }
    }
}
